package com.delivery.controller.user;

import com.delivery.entity.Setmeal;
import com.delivery.result.Result;
import com.delivery.service.SetmealService;
import com.delivery.vo.ComboContainedDishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("user.SetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {

    @Autowired
    SetmealService setmealService;

    /**
     * 获取某分类下的套餐列表
     * @param categoryId 分类ID
     * @return
     */
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmeal", key = "#categoryId")
    public Result<List<Setmeal>> getCombosByCategoryId(Long categoryId){
        List<Setmeal> setmeals = setmealService.getCombosByCategoryId(categoryId);
        return Result.success(setmeals);
    }

    /**
     * 获取套餐内包含的菜品
     * @param id 套餐ID
     * @return
     */
    @GetMapping("/dish/{id}")
    public Result<List<ComboContainedDishVO>> getContainedDishesByComboId(@PathVariable Long id){
        List<ComboContainedDishVO> comboContainedDishVOS = setmealService.getContainedDishesByComboId(id);
        return Result.success(comboContainedDishVOS);
    }
}
